package greed;

import java.util.Arrays;
import java.util.Collections;

//https://leetcode.cn/leetbook/read/illustration-of-algorithm/lhrww7/
public class LCR_164破解闯关密码 {
    public static String crackPassword(int[] password) {
        String[] strs = new String[password.length];
        for(int i = 0; i < password.length; i++)
            strs[i] = String.valueOf(password[i]);
        Arrays.sort(strs, (x, y) -> (x + y).compareTo(y + x));//1交换位置，-1不交换
        Arrays.sort(strs, Collections.reverseOrder());
        StringBuilder res = new StringBuilder();
        for(String s : strs)
            res.append(s);
        return res.toString();
    }

    public static void main(String[] args) {
        int[] password = {15, 8, 7};
        System.out.println(crackPassword(password));
    }
}
